home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / autofind / source / adlayout.sx next >
Encoding:
Text File  |  1996-05-21  |  3.7 KB  |  119 lines  |  [TEXT/ttxt]

  1. --<<<
  2. -- Filename:
  3. --     adlayout.sx
  4. --
  5. -- Other Files Required: 
  6. --     None
  7. --
  8. -- Purpose: 
  9. --     Defines the ClassifiedAds page layout and its contents
  10. --
  11. -- Specialized Classes:
  12. --     PageElementButton - mixes in the actuator class with the PageElement class
  13. --     ThreeAdPageTemplate - defines a page layout with three ads
  14. --
  15. -- Author:
  16. --     Steve Gano, Dionn M. Stewart, Felicia Santelli
  17.  
  18. in module Autofinder
  19.  
  20. -- Define the layout we want to represent our data
  21. class ThreeAdPageTemplate (PageLayer)
  22. end
  23.  
  24.  
  25. -- A method to create a textpresenter presenter for each ad on the page.  
  26. method makeAdtextpresenter self {class ThreeAdPageTemplate} ->
  27. (
  28.     local tb
  29.     tb := new textpresenter boundary:(new rect x2:200 y2:166) target:("" as Text)
  30.     setDefaultAttr tb @font (new platformfont name:"Times")
  31.     setDefaultAttr tb @size 18
  32.     setDefaultAttr tb @leading 18
  33.     setDefaultAttr tb @alignment @flush
  34.     tb
  35. )
  36.  
  37. -- A method to create a twoDshape bitmap presenter for each ad on the page.
  38. method makeAdPicShape self {class ThreeAdPageTemplate} ->
  39. (
  40.     new TwoDShape boundary:(new rect x2:200 y2:163) stroke:blackBrush fill:blackBrush
  41. )
  42.  
  43. method makeAdElement self {class ThreeAdPageTemplate} adPos picPos textPos ->
  44. (
  45.     local picbounds:= new rect x2:200 y2:163
  46.     local textbounds:= new rect x2:200 y2:166
  47.  
  48.     local adPic:= new pageElement boundary:picBounds \
  49.         presenter:(makeAdPicShape self)\
  50.         target:(e -> e.presenter.boundary := (getPageData e.presentedBy)[adPos].adPic)
  51.     adPic.x := picPos.x
  52.     adPic.y := picPos.y
  53.     prepend self adPic
  54.  
  55.     local adText:= new pageElement boundary:textBounds\
  56.         presenter:(makeAdtextpresenter self)\
  57.         target:(e -> e.presenter.target:= ((getPageData e.presentedBy)[adPos].adText as Text))
  58.     adText.x := textPos.x
  59.     adText.y := textPos.y
  60.     prepend self adText
  61. )    
  62.  
  63.  
  64. -- instantiate all the page elements of the layout
  65. method init self {class ThreeAdPageTemplate} #rest args #key media:->
  66. (
  67.     apply nextMethod self args
  68.     self.stroke := whiteBrush
  69.  
  70.     -- CREATE ELEMENTS USED IN THE CLASSIFIED AD PAGE TEMPLATE
  71.     -- The background picture element for the classified ads
  72.     local bkgndPic := new pageElement boundary:media["bkgndPic"].boundary\
  73.         presenter:media["bkgndPic"] target:media["bkgndPic"].boundary
  74.     append self bkgndPic
  75.  
  76.     -- Make a text box for showing the current page number
  77.     local pageNumberTB:= new textpresenter boundary:(new rect x2:100 y2:30)\
  78.         target:("" as Text)
  79.     setDefaultAttr pageNumberTB @font (new platformfont name:"Times")
  80.     setDefaultAttr pageNumberTB @size 12
  81.     setDefaultAttr pageNumberTB @weight @heavy
  82.     setDefaultAttr pageNumberTB @leading 14
  83.     setDefaultAttr pageNumberTB @alignment @flushToEnd
  84.     
  85.     -- Make the page element for the text box
  86.     local pageNumElement:= new PageElement boundary:pageNumberTB.boundary\
  87.         presenter:pageNumberTB\
  88.         target:(e -> (e.presenter.target:= (currentpage e.presentedby) as Text))
  89.     pageNumElement.x:= 530
  90.     pageNumElement.y:= 455
  91.     prepend self pageNumElement
  92.  
  93.     -- Make the picture and text elements for all three ads on the page
  94.     makeAdElement self 1 (new point x:12 y:118) (new point x:12 y:290)
  95.     makeAdElement self 2 (new point x:221 y:118) (new point x:221 y:290)
  96.     makeAdElement self 3 (new point x:430 y:118) (new point x:430 y:290)
  97.     
  98.     self
  99. )
  100.  
  101. -- SOME CONVENIENCE METHODS FOR THE THREEADPAGETEMPLATE
  102. --    pageData self
  103. --        Simply passes the request for the data on a page up to the document.
  104. -- currentPage self
  105. --        Invoked as the data method for the page element that displays the
  106. --        current page number.  It returns a string "Page <i> of <n>".
  107. method getPageData self {class ThreeAdPageTemplate} -> 
  108. (
  109.     self.presentedBy.presentedBy.pageData
  110. )
  111.  
  112. method currentPage self {class ThreeAdPageTemplate}-> 
  113. (
  114.     ("Page " + (self.presentedBy.presentedBy.cursor as string) + 
  115.                     " of " + ((size self.presentedBy.presentedBy) as string)) as Text
  116. )
  117. "Compiled adlayout.sx"
  118. -->>>
  119.